<template>
  <div>
    <img class="img" src="@/assets/header.jpg">
  </div>
  <div class="container">
    <div class="card-wrapper">
      <el-card
          v-for="item in data"
          :key="item.id"
          class="box-card"
      >
        <div slot="header" class="card-header">
          <span>{{ item.name }}</span>
          <el-radio class="radio" size="small" check="false" v-model="defaultRadio" @click="finish(item)"></el-radio>
        </div>
        <div class="text item card-content" @click="view(item)">{{ item.description }}</div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import {reactive, ref, onMounted, getCurrentInstance} from 'vue'
import Url from "@/consts/Url";
import {RESPONSE_ERROR_CODE} from '@/consts/Codes'
import {ElMessage} from 'element-plus';
import DateUtils from "@/utils/DateUtils";

const {proxy} = getCurrentInstance();

let data = reactive([]);

let defaultRadio = ref(0);

async function loadData() {
  let params = {
    date: DateUtils.formatDate(new Date().getTime())
  }
  const response = await proxy.$request.get(Url.RECALL.RECALL_MEMORY.value, params);
  if (response.code === RESPONSE_ERROR_CODE.SUCCESS.value) {
    data.splice(0, data.length);
    data.push(...response.data);
  } else {
    ElMessage.error("获取数据错误");
  }
}

onMounted(() => {
  loadData();
});

const view = (item) => {
  console.log(JSON.stringify(item));
  window.open(item.path, '_blank');
}

async function finish(item) {
  let params = {
    id: item.id
  }
  const response = await proxy.$request.get(Url.RECALL.RECALL_FINISH.value, params);
  if (response.code === RESPONSE_ERROR_CODE.SUCCESS.value) {
    loadData();
  } else {
    ElMessage.error(response.message);
  }
}

</script>

<style scoped>

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  min-height: 100vh;
  align-items: flex-start; /* 将容器内容垂直居上 */
  background-color: #F2F2F2;
  background-size: cover;
  background-blend-mode: lighten;
}

.card-wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 1200px;
  padding: 10px;
}

.box-card {
  cursor: pointer;
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
  border-radius: 10px;
  overflow: hidden;
  background-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.box-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.card-header {
  font-weight: bold;
  font-size: 1.2em;
  background-color: #729dcf;
  color: #fff;
  padding: 10px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.card-content {
  padding: 20px;
  color: #333;
  font-size: 1em;
  line-height: 1.5;
}

.img {
  width: 100%;
  height: 300px;
  object-fit: cover; /* 图片适应展示 */
  overflow: hidden;
}

.radio {
  float: right;
  padding: 3px 0;
  font-size: 24px;
  transform: scale(2);
}
</style>